package com.ruixinzheng.databindingdemo.model;

import android.content.Context;
import android.content.SharedPreferences;

import com.ruixinzheng.databindingdemo.AppApplication;


public class MainRepo {

    private static MainRepo sInstance = null;
    private SharedPreferences mPfs;

    public static MainRepo getInstance() {
        if (sInstance == null) {
            synchronized (MainRepo.class) {
                if (sInstance == null) {
                    sInstance = new MainRepo();
                }
            }
        }
        return sInstance;
    }

    private MainRepo() {
        Context context = AppApplication.getInstance();
        mPfs = context.getSharedPreferences("app", Context.MODE_PRIVATE);
    }

    public int getCount() {
        return mPfs.getInt("count", 0);
    }

    public int increaseCount() {
        int count = getCount() + 1;
        mPfs.edit().putInt("count", count).apply();
        return count;
    }
}
